config := meta.(*Config)

project, err := getProject(d, config)
if err != nil {
 	return nil, err
}

userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
	return nil, err
}

<% if object.name == 'Disk' -%>
if v, ok := d.GetOk("type"); ok {
	log.Printf("[DEBUG] Loading disk type: %s", v.(string))
	diskType, err := readDiskType(config, d, v.(string))
	if err != nil {
		return nil, fmt.Errorf(
			"Error loading disk type '%s': %s",
			v.(string), err)
	}

	obj["type"] = diskType.RelativeLink()
}
<% elsif object.name == 'RegionDisk' -%>
if v, ok := d.GetOk("type"); ok {
	log.Printf("[DEBUG] Loading disk type: %s", v.(string))
	diskType, err := readRegionDiskType(config, d, v.(string))
	if err != nil {
		return nil, fmt.Errorf(
			"Error loading disk type '%s': %s",
			v.(string), err)
	}

	obj["type"] = diskType.RelativeLink()
}
<%
else
  raise 'disk.erb included in non-disk type #{object.name}'
end
-%>

if v, ok := d.GetOk("image"); ok {
	log.Printf("[DEBUG] Resolving image name: %s", v.(string))
	imageUrl, err := resolveImage(config, project, v.(string), userAgent)
	if err != nil {
		return nil, fmt.Errorf(
			"Error resolving image name '%s': %s",
			v.(string), err)
	}

	obj["sourceImage"] = imageUrl
	log.Printf("[DEBUG] Image name resolved to: %s", imageUrl)
}

return obj, nil
